import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/colors.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/button_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/widgets.dart';
import 'package:appflutterhomeschool/view_model/login/register_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///用户：Nine Tailed Fox
///时间：2020/6/10
///邮箱：1037438704@qq.com
///功能：0 注册  1 忘记密码  2 微信登录  3修改绑定手机号


class RegisterPage extends StatefulWidget {
  final int pageTag;

  RegisterPage({this.pageTag});

  @override
  _RegisterPageState createState() => _RegisterPageState();
}

class _RegisterPageState extends State<RegisterPage> {

  @override
  Widget build(BuildContext context) {
    return ProviderWidget<RegisterViewModel>(
      model: RegisterViewModel(context, widget.pageTag),
      onModelReady: (value) => value.initView(),
      builder: (context, viewModel, child) {
        return GestureDetector(
          onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
          child: Scaffold(
            resizeToAvoidBottomInset: false,
            backgroundColor: Colors.white,
            appBar: AppBar(
              brightness: Brightness.light,
              elevation: 0,
              leading: IconButton(
                icon: Icon(Icons.clear, color: Colors.black),
                onPressed: () => Navigator.pop(context),
              ),
            ),
            body: Container(
              padding: EdgeInsets.only(
                  left: ScreenUtil().setWidth(125),
                  right: ScreenUtil().setWidth(125)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Container(
                      alignment: Alignment.center,
                      child: Text(viewModel.titleTar,
                          style: TextStyles.textDark70)),
                  viewModel.textVisition(),
                  SizedBox(height: ScreenUtil().setWidth(100)),
                  TextFieldWidget(
                      textEditingController: viewModel.phoneTextEditing,
                      hintText: "请输入手机号码",
//                      valueChanged: (value) {
//                        viewModel.phoneText = value;
//                      }
                      ),
                  Stack(alignment: Alignment.centerRight, children: <Widget>[
                    TextFieldWidget(
                        length: 6,
                        textEditingController: viewModel.vCodeTextEditing,
                        hintText: "请输入验证码",
//                        valueChanged: viewModel.getVerificationCodeText

                    ),
                    GestureDetector(
                      child: Text(
                        viewModel.codeCountdownStr ?? "获取验证码",
                        style: TextStyle(
                          fontSize: ScreenUtil().setWidth(43),
                          color: viewModel.resendColor,
                        ),
                      ),
                      onTap: viewModel.reGetCountdown,
                    )
                  ]),
                  Visibility(
                    visible: widget.pageTag != 3,
                    child: TextFieldWidget(
                      textEditingController: viewModel.passwordTextEditing,
                      hintText: "请输入密码",
                      obscureText: viewModel.obscureText,
                      iconEye: GestureDetector(
                        child: Icon(
                          viewModel.obscureText
                              ? Icons.visibility_off
                              : Icons.remove_red_eye,
                          color: Colours.text_dark,
                          size: ScreenUtil().setSp(62),
                        ),
                        onTap: () => viewModel.initEvent(0),
                      ),
                    ),
                  ),
                  SizedBox(height: ScreenUtil().setSp(80)),
                  SureMaterialButton(
                    buttonName: viewModel.buttonName,
                    onPressed: viewModel.sureOnTap,
                  ),
                  SizedBox(height: ScreenUtil().setSp(43)),
                  RegistrationAgreementWidget(viewModel),
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}
